package HomeWork.Chapter04;

/**
 * Enjoy programming!!!
 * Time: 2021/11/27 -  16:36
 */

import java.util.Scanner;

public class Fraction_ {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Fraction a = new Fraction(in.nextInt(), in.nextInt());
        Fraction b = new Fraction(in.nextInt(), in.nextInt());
        a.print();
        b.print();
        a.plus(b).print();
        a.multiply(b).print();
        in.close();
    }
}

class Fraction {
    private int son;
    private int mother;

    public Fraction(int x, int y) {
        son = x;
        mother = y;
    }

    public void print() {
        System.out.printf("%d/%d ", son, mother);
    }

    public Fraction plus(Fraction n) {

        int b = Fraction.divisor(this.mother, n.mother);//最大公约数
        int s = n.mother * this.mother / b;//最小公倍数

        Fraction result = new Fraction(n.son * s / n.mother + this.son * s / this.mother, s);
        int c = Fraction.divisor(result.son, result.mother);
        result.son /= c;
        result.mother /= c;
        return result;
    }

    public Fraction multiply(Fraction f) {

        Fraction result = new Fraction(f.son * this.son, f.mother * this.mother);
        int c = Fraction.divisor(result.son, result.mother);
        result.son /= c;
        result.mother /= c;
        return result;

    }

    //    static public int divisor(int a, int b){
//        return a % b == 0 ? b : divisor(b, a % b);
//    }
//}
    public static int divisor(int m, int m1) {
        if (m < m1) {
            int temp = m1;
            m1 = m;
            m = temp;
        }
        while (m % m1 != 0) {
            int temp = m1 % m;
            m1 = m;
            m = temp;
        }
        return m1;
    }
}


